class Solution {
public:
    vector<int> getAverages(vector<int>& nums, int k) {
        int n=nums.size();
        vector<int> ans(n,-1);
        if(n<2*k+1)
        {
            return ans;
        }
        long long sum =accumulate(nums.begin(),nums.begin()+2*k+1,0LL);
        int mid=k;
        while(mid+k<n)
        {
            ans[mid]=sum/(2*k+1);
            if(0<=mid-k)
                sum-=nums[mid-k];
            if(mid+k+1<n)
                sum+=nums[mid+k+1];
            mid++;
        }
        return ans;
        
    }
};